package com.firmye.codegenerator.utils;

import java.math.BigDecimal;
import java.util.Date;

public class ClassUtil {

    // 获取匹配类型
    public static Class getClass(String columnName) {
        if ("TINYINT".equals(columnName) || "SMALLINT".equals(columnName) || "MEDIUMINT".equals(columnName)
                || "INTEGER".equals(columnName) || "INT".equals(columnName)) {
            return Integer.class;
        } else if ("VARCHAR".equals(columnName) || "CHAR".equals(columnName) || "TEXT".equals(columnName)) {
            return String.class;
        } else if ("BLOB".equals(columnName) || "BINARY".equals(columnName) || "VARBINARY".equals(columnName)
                || "TINYBLOB".equals(columnName) || "MEDIUMBLOB".equals(columnName) || "LONGBLOB".equals(columnName)) {
            return byte[].class;
        } else if ("BIT".equals(columnName) || "BOOL".equals(columnName) || "BOOLEAN".equals(columnName)) {
            return Boolean.class;
        } else if ("BIGINT".equals(columnName)) {
            return Long.class;
        } else if ("FLOAT".equals(columnName)) {
            return Float.class;
        } else if ("DOUBLE".equals(columnName)) {
            return Double.class;
        } else if ("DECIMAL".equals(columnName)) {
            return BigDecimal.class;
        } else if ("DATE".equals(columnName) || "DATETIME".equals(columnName) || "TIMESTAMP".equals(columnName)
                || "TIME".equals(columnName)) {
            return Date.class;
        }

        return null;
    }

    public static String getByClass(Class clazz) {
        if (null != clazz.getPackage() && !(clazz.getPackage().toString().indexOf("package java.lang") != -1))
            return clazz.getName();
        return null;
    }

}
